#include <iostream>
#include "PKW.h"

static const double PI = 3.141592653589793238462;


PKW::PKW( size_t wheel_diameter, WheelSpinSensor * sens ) :
	mDiameter(wheel_diameter)
{
	mSensor = sens;

	if (mSensor == NULL) {
		mRevolutions = 0;
	}
}

void PKW::Process()
{
	if (mSensor != NULL) {
		mRevolutions = mSensor->GetRevolutions();
	}

	Notify();

	// Debug output.
	std::cout << "updating data! ";
	std::cout << "speed: " << GetCurrentSpeed() << " km/h, ";
	std::cout << "distance: " << ((GetCurrentSpeed() / 3.6) * 0.5) << " m/s" << std::endl;
}

double PKW::GetCurrentSpeed() const
{
	return ((double)mRevolutions / 60) * ((double)mDiameter / 1000) * PI * 3.6;
}